library(gridExtra)
library(ggplot2)
library(foreign)

# Set working directory. Please set your own
setwd("~/Desktop/PSRM Replication")


data <- read.dta("Data/sameaveragecontrolsoneoutInt.dta")

theme_base1 <- 
  theme_minimal(base_size=10)  + 
  theme(legend.position=c(0.1, .1),  legend.key.size = unit(1,"line"),
        axis.text.y=element_text(size=10),axis.title.x=element_text(size=10),axis.title.y=element_text(size=10),
        axis.text.x=element_text(size=6),
        plot.title = element_text(size=10, hjust= 0.5))



data2<-data[data$id2!=2 , ]
data2$grp<-as.factor(data2$id2)


main<-ggplot(data2, aes(x=id1, y =estimate,color=grp)) +   
  geom_point(size = 2,position=position_dodge(0.35)) + 
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.7,position=position_dodge(width=0.35))+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=1.6,position=position_dodge(width=0.35))+
  scale_x_continuous(name="Election Missing from the Analysis", breaks = c(1956,1958,1960,1962,1964,1966,1968,1970,1972,1974,1976,1978,1980,1982,1984,1986,1988,1990,1992,1994,1996,1998,2000,2002,2004,2006,2008,2010,2012,2014,2016,2018))+
  scale_y_continuous(limits = c(-.02, .1))+ 
  scale_color_manual(name="Outcome Election",labels=c("Presidential","Midterm"),values=c("blue","red")) + 
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Difference in Probability of Voting:\n Same vs different type of election") 
main

ggsave("Graphs/AllaverageOneOutInt.pdf", width = 22, height = 18, units = "cm")  